import { createRouter, createWebHashHistory } from 'vue-router'
import { ElMessage } from 'element-plus'
import routes from "./routes.js";

const router = createRouter({
  history: createWebHashHistory(process.env.BASE_URL),
  routes
})

router.beforeEach((to)=>{
  // 不需要授权的页面可以直接放行
  if(to.meta.isPublic){
    return true;
  }
  if( sessionStorage.getItem("token") ){
    return true;
  }
  ElMessage.error("未授权访问，请联系管理员")
  return {
    name:"login"
  }
})

export default router
